using System.Collections;
using System.Collections.Generic;

namespace MathService.MathParser
{
    public class ComplexOperatorCollection : IEnumerable<ComplexOperatorItem>
    {
        private readonly List<ComplexOperatorItem> f_Operators = new List<ComplexOperatorItem>();

        private readonly MathExpression f_Expression;

        public int Count { get { return f_Operators.Count; } }

        public ComplexOperatorCollection(MathExpression Expression) { f_Expression = Expression; }

        public bool Add(ComplexOperatorItem Operator)
        {
            if(f_Operators.Exists(o => o.Name == Operator.Name)) return false;
            f_Operators.Add(Operator);
            return true;
        }

        public IEnumerator<ComplexOperatorItem> GetEnumerator() { return f_Operators.GetEnumerator(); }

        IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable)f_Operators).GetEnumerator(); }

        public override string ToString() { return string.Format("Complex operator collection > count = {0}", Count); }
    }
}